package cn.edu.sdjzu.nacosconsumerservice;


import cn.edu.sdjzu.nacosconsumerservice.client.ProviderServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient // 启用服务发现
@EnableFeignClients // 启用 OpenFeign 客户端扫描 (会扫描 @FeignClient 注解的接口)
public class NacosConsumerServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosConsumerServiceApplication.class, args);
    }
}

@RestController
class ConsumerController {

    // 注入 Feign 客户端
    @Autowired
    private ProviderServiceClient providerServiceClient;

    @GetMapping("/call/hello/{name}")
    public String callProviderHello(@PathVariable String name) {
        System.out.println("Consumer attempting to call provider...");
        // 使用 Feign 客户端像调用本地方法一样调用远程服务
        String result = providerServiceClient.callHello(name);
        System.out.println("Consumer received result: " + result);
        return "Consumer Feign Call Result: " + result;
    }
}
